package edu.gatech.cs2340.mule.view;

import javax.swing.*;

import edu.gatech.cs2340.mule.model.Player;
import edu.gatech.cs2340.mule.presenter.MuleGamePresenter;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

/**
 * 
 * Shows the current player's information
 * 
 * @author JR O'Donnell
 *
 */
public class PlayerInfoPanel extends JPanel {
	
	private JLabel	moneyAmountLabel;
	private JLabel foodAmountLabel;
	private JLabel energyAmountLabel;
	private JLabel smithoreAmountLabel;
	private JButton passButton;
	private JButton saveButton;
	
	/**
	 * Create the panel.
	 */
	public PlayerInfoPanel() {
		setLayout(new GridLayout(5, 2));
		setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		
		JLabel moneyIconLabel = new JLabel(new ImageIcon("Images\\icon_money.png"));
		add(moneyIconLabel);
		
		moneyAmountLabel = new JLabel();
		moneyAmountLabel.setForeground(MuleGamePresenter.FOREGROUND_COLOR);
		moneyAmountLabel.setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		add(moneyAmountLabel);
		
		JLabel foodIconLabel = new JLabel(new ImageIcon("Images\\icon_food.png"));
		add(foodIconLabel);
		
		foodAmountLabel = new JLabel();
		foodAmountLabel.setForeground(MuleGamePresenter.FOREGROUND_COLOR);
		foodAmountLabel.setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		add(foodAmountLabel);
		
		JLabel energyIconLabel = new JLabel(new ImageIcon("Images\\icon_energy.png"));
		add(energyIconLabel);
		
		energyAmountLabel = new JLabel();
		energyAmountLabel.setForeground(MuleGamePresenter.FOREGROUND_COLOR);
		energyAmountLabel.setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		add(energyAmountLabel);
		
		JLabel smithoreIconLabel = new JLabel(new ImageIcon("Images\\icon_smithore.png"));
		add(smithoreIconLabel);
		
		smithoreAmountLabel = new JLabel();
		smithoreAmountLabel.setForeground(MuleGamePresenter.FOREGROUND_COLOR);
		smithoreAmountLabel.setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		add(smithoreAmountLabel);
		
		passButton = new JButton("Pass");
		passButton.setBackground(MuleGamePresenter.FOREGROUND_COLOR);
		passButton.setForeground(MuleGamePresenter.BACKGROUND_COLOR);
		add(passButton);
		
		saveButton = new JButton("Save Game");
		saveButton.setBackground(MuleGamePresenter.FOREGROUND_COLOR);
		saveButton.setForeground(MuleGamePresenter.BACKGROUND_COLOR);
		add(saveButton);

	}
	
	/**
	 * Removes the pass button
	 */
	public void removePass() {
		remove(passButton);
	}
	
	/**
	 * Adds the specified listener to the pass button.
	 * 
	 * @param a The action listener to be added to the pass button
	 */
	public void addPassListener(ActionListener a) {
		passButton.addActionListener(a);
	}
	
	/**
	 * Adds the specified listener to the save button.
	 * 
	 * @param a The action listener to be added to the save button
	 */
	public void addSaveListener(ActionListener a) {
		saveButton.addActionListener(a);
	}
	
	/**
	 * Update information to the current Player's information
	 * 
	 * @param currentPlayer The currentPlayer to display information about
	 */
	public void updatePlayerInfoPanel(Player currentPlayer) {
		moneyAmountLabel.setText("" + currentPlayer.getMoneyAmount());
		foodAmountLabel.setText("" + currentPlayer.getFoodAmount());
		energyAmountLabel.setText("" + currentPlayer.getEnergyAmount());
		smithoreAmountLabel.setText("" + currentPlayer.getSmithOreAmount());
	}
}
